# coding: utf-8

# __LINE__关键字
puts __LINE__

# case、when、then、else和end关键字
case "段光伟"
when /段.*/ then
	puts "你姓段"
else
	puts "非我族类"
end

# begin、raise、rescue、ensure和end关键字
begin
	raise Exception.new
rescue Exception => e
	puts "出现异常了"
ensure
	puts "一定会执行"
end

# not关键字
puts (not true)

# __ENCODING__关键字
puts __ENCODING__

# class关键字
class TestClass
end

puts TestClass

# false关键字
puts false

# or关键字
puts true or false

# true关键字
puts true

# __FILE__关键字
puts __FILE__

# def 关键字
def test_method()
	puts "test_method"
end

test_method

# for、in和end关键字
for item in 1..10
	puts item
end

# redo关键字
sum = 0
for item in 1..10
	sum += 1
	redo if sum == 3
end

puts sum

# alias和undef关键字
def test_mtehod()
	puts "test_mtehod"
end

test_mtehod
undef test_mtehod

# BEGIN和END关键字
BEGIN{
	puts 1
}
BEGIN{
	puts 2
}
END{
	puts 2
}
END{
	puts 1
}

# defined?关键字
puts "未定义" if not defined? 未定义

# if、then、elsif、else和end关键字
x = 1
y = 2

if x < y then
	puts "#{x} < #{y}"
elsif x == y then
	puts "#{x} == #{y}"
else
	puts "#{x} > #{y}"
end

# unless、then、else和end关键字
x = 1
y = 2

unless x >= y then
	puts "#{x} < #{y}"
else
	puts "#{x} >= #{y}"
end

# do和end关键字
3.times do
	puts "段光伟"
end

# retry关键字
current_retry = 0
begin
	puts "执行两次"
	raise
rescue
	if current_retry == 0
		current_retry += 1
		retry
	end
end

# until关键字
x = 1
until x == 6
	puts x
	x += 1
end

# module关键字
module TestModule
end

puts TestModule

# and 关键字
puts true and true

# next关键字
x = 0
until x == 6
	x += 1
	next if x == 2
	puts x
end

# self关键字
puts self

# while关键字
x = 1
while x <= 5
	puts x
	x += 1
end

# nil关键字
puts nil.class

# super关键字
class Base
	def say()
		puts "Base"
	end
end

class Child < Base
	def say()
		super()
		puts "Child"
	end
end

Child.new.say

# break关键字
x = 1
while true
	puts x

	break if x == 5

	x += 1
end

# yield关键字
def yield_test()
	yield 2, 2
end

yield_test { |x, y| puts x, y }